import 'package:efood_multivendor/data/model/response/order_model.dart';
import 'package:efood_multivendor/data/model/response/product_model.dart';
import 'package:efood_multivendor/data/model/response/restaurant_model.dart';

class OrderDetails {
  int? id;
  int? userId;
  double? orderAmount;
  String? paymentStatus;
  String? orderStatus;
  String? paymentMethod;
  String? transactionReference;
  String? deliveryAddressId;
  int? deliveryManId;
  String? otp;
  String? orderNote;
  String? orderType;
  int? checked;
  int? restaurantId;
  String? createdAt;
  String? updatedAt;
  double? deliveryCharge;
  String? scheduleAt;
  int? scheduled;
  String? pending;
  String? accepted;
  String? confirmed;
  String? processing;
  String? handover;
  String? pickedUp;
  String? delivered;
  String? canceled;

  int? isCampaign;

  int? languagePrefFee;

  int? isAssign;
  int? isAccepted;
  double? serviceCharge;

  int? tip;

  double? itemAmount;
  double? addonAmount;
  Restaurant? restaurant;
  List<Details>? details;
  double? subTotal;
  double? couponDiscountAmount;
  double? totalDiscountAmount;
  DeliveryMan? deliveryMan;
  int? remainingTime;
  int? bonusPoint;

  OrderDetails(
      {this.id,
      this.userId,
      this.orderAmount,
      this.paymentStatus,
      this.orderStatus,
      //this.totalTaxAmount,
      this.paymentMethod,
      this.transactionReference,
      this.deliveryAddressId,
      this.deliveryManId,
      this.orderNote,
      this.orderType,
      this.checked,
      this.restaurantId,
      this.createdAt,
      this.updatedAt,
      this.deliveryCharge,
      this.scheduleAt,
      this.pending,
      this.accepted,
      this.confirmed,
      this.processing,
      this.handover,
      this.pickedUp,
      this.delivered,
      this.canceled,
      this.isCampaign,
      this.languagePrefFee,
      this.isAssign,
      this.isAccepted,
      this.serviceCharge,
      this.tip,
      this.itemAmount,
      this.addonAmount,
      this.restaurant,
      this.details,
      this.subTotal,
      this.couponDiscountAmount,
      this.scheduled,
      this.otp,
      this.totalDiscountAmount,
      this.deliveryMan,
      this.remainingTime,
      this.bonusPoint});

  factory OrderDetails.fromJson(Map<String, dynamic> json) {
    return OrderDetails(
        id: json['id'],
        userId: json['user_id'],
        orderAmount: json['order_amount'],
        paymentStatus: json['payment_status'],
        orderStatus: json['order_status'],
        //  totalTaxAmount: json['total_tax_amount'],
        paymentMethod: json['payment_method'],
        transactionReference: json['transaction_reference'],
        deliveryAddressId: json['delivery_address_id'],
        deliveryManId: json['delivery_man_id'],
        orderNote: json['order_note'],
        orderType: json['order_type'],
        checked: json['checked'],
        restaurantId: json['restaurant_id'],
        createdAt: json['created_at'],
        updatedAt: json['updated_at'],
        deliveryCharge: json['delivery_charge'],
        scheduleAt: json['schedule_at'],
        pending: json['pending'],
        accepted: json['accepted'],
        confirmed: json['confirmed'],
        processing: json['processing'],
        handover: json['handover'],
        pickedUp: json['picked_up'],
        delivered: json['delivered'],
        canceled: json['canceled'],
        isCampaign: json['is_campaign'],
        languagePrefFee: json['language_pref_fee'],
        isAssign: json['is_assign'],
        isAccepted: json['is_accepted'],
        serviceCharge: json['service_charge'],
        tip: json['tip'],
        itemAmount: json['item_amount'],
        addonAmount: json['addon_amount'],
        restaurant: Restaurant.fromJson(json['restaurant']),
        details:
            (json['details'] as List).map((i) => Details.fromJson(i)).toList(),
        subTotal: json['subtotal'],
        couponDiscountAmount: json['coupon_discount_amount'],
        scheduled: json['scheduled'],
        otp: json['otp'],
        totalDiscountAmount: json['total_discount_amount'],
        deliveryMan: json['delivery_man'] != null
            ? new DeliveryMan.fromJson(json['delivery_man'])
            : null,
        remainingTime: json['cancel_timeout'],
        bonusPoint: json['bonus_point']);
  }
}

class Details {
  int? id;
  int? foodId;
  int? orderId;
  double? price;
  ProductWithQuantity? foodDetails;
  //List<String> variation;
  double? discountOnFood;
  String? discountType;
  int? quantity;
  double? taxAmount;
  String? variant;
  String? createdAt;
  String? updatedAt;
  int? itemCampaignId;
  double? totalAddOnPrice;
  int? freeQuantity;
  bool? reviewed;
  double? languagePrefFee;
  List<AddOnsOrderDetail>? addOns;

  Details(
      {this.id,
      this.foodId,
      this.orderId,
      this.price,
      this.foodDetails,
      //this.variation,
      this.discountOnFood,
      this.discountType,
      this.quantity,
      this.taxAmount,
      this.variant,
      this.createdAt,
      this.updatedAt,
      this.itemCampaignId,
      this.totalAddOnPrice,
      this.freeQuantity,
      this.reviewed,
      this.languagePrefFee,
      this.addOns});

  factory Details.fromJson(Map<String, dynamic> json) {
    return Details(
      id: json['id'],
      foodId: json['food_id'],
      orderId: json['order_id'],
      price: json['price'],
      foodDetails: ProductWithQuantity.fromJson(json['food_details']),
      addOns: (json['add_ons'] as List)
          .map((i) => AddOnsOrderDetail.fromJson(i))
          .toList(),
      discountOnFood: json['discount_on_food'],
      discountType: json['discount_type'],
      quantity: json['quantity'],
      taxAmount: json['tax_amount'],
      variant: json['variant'],
      createdAt: json['created_at'],
      updatedAt: json['updated_at'],
      itemCampaignId: json['item_campaign_id'],
      totalAddOnPrice: json['total_add_on_price'],
      freeQuantity: json['free_quantity'],
      reviewed: json['reviewed'],
      languagePrefFee: json['language_pref_fee'],
    );
  }
}

class AddOnsOrderDetail {
  int? id;
  String? name;
  double? price;
  int? quantity;

  AddOnsOrderDetail({this.id, this.name, this.price});

  AddOnsOrderDetail.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    name = json['name'];
    price = json['price'].toDouble();
    quantity = json['quantity'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['name'] = this.name;
    data['price'] = this.price;
    data['quantity'] = this.quantity;
    return data;
  }
}
